/*     */ package cc.s2m.web.s2mBlog.controller.admin;
/*     */ 
/*     */ import cc.s2m.util.BeanConverter;
/*     */ import cc.s2m.util.Page;
/*     */ import cc.s2m.web.s2mBlog.controller.base.BaseController;
/*     */ import cc.s2m.web.s2mBlog.pojo.Admin;
/*     */ import cc.s2m.web.s2mBlog.pojo.AdminRoles;
/*     */ import cc.s2m.web.s2mBlog.pojo.Roles;
/*     */ import cc.s2m.web.s2mBlog.service.IAdmin;
/*     */ import cc.s2m.web.s2mBlog.service.IAdminRoles;
/*     */ import cc.s2m.web.s2mBlog.service.IRoles;
/*     */ import com.google.common.base.Strings;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.codec.digest.DigestUtils;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.Model;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ 
/*     */ @Controller("admin_AdminController")
/*     */ @RequestMapping({"/admin/admin"})
/*     */ public class AdminController extends BaseController
/*     */ {
/*     */ 
/*     */   @Autowired
/*     */   private IAdmin adminService;
/*     */ 
/*     */   @Autowired
/*     */   private IAdminRoles adminRolesService;
/*     */ 
/*     */   @Autowired
/*     */   private IRoles rolesService;
/*     */ 
/*     */   @RequestMapping({"/list"})
/*     */   public String list(Model model, Admin bean, Integer page)
/*     */   {
/*  39 */     if (page == null) page = Integer.valueOf(1);
/*  40 */     Map map = new HashMap();
/*  41 */     if (bean != null) {
/*  42 */       map.putAll(BeanConverter.toMap(bean, false));
/*  43 */       model.addAttribute("bean", bean);
/*     */     }
/*  45 */     Page pageBean = this.adminService.getPage(page.intValue(), 50, null, map);
/*  46 */     model.addAttribute("pageBean", pageBean);
/*  47 */     return "admin/admin";
/*     */   }
/*     */   @RequestMapping(value={"/stop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   @ResponseBody
/*     */   public String stop(Integer id) {
/*  53 */     Admin bean = (Admin)this.adminService.selectByPrimaryKey(id);
/*  54 */     if (bean == null) {
/*  55 */       return "noAdmin";
/*     */     }
/*  57 */     bean.setIsLock(Boolean.valueOf(!bean.getIsLock().booleanValue()));
/*  58 */     this.adminService.updateByPrimaryKey(bean);
/*  59 */     return "success";
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"/add"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public String add(Model model, Integer id) {
/*  64 */     if (id != null) {
/*  65 */       Admin bean = (Admin)this.adminService.selectByPrimaryKey(id);
/*  66 */       model.addAttribute("bean", bean);
/*     */ 
/*  68 */       AdminRoles condition = new AdminRoles();
/*  69 */       condition.setAid(id);
/*  70 */       List myRoles = this.adminRolesService.getList(condition, null);
/*  71 */       model.addAttribute("myRoles", myRoles);
/*     */     }
/*     */ 
/*  74 */     List roles = this.rolesService.getList(new Roles(), null);
/*  75 */     model.addAttribute("roles", roles);
/*  76 */     return "admin/admin_add";
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"/view"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public String view(Model model, Integer id) {
/*  81 */     if (id != null) {
/*  82 */       Admin bean = (Admin)this.adminService.selectByPrimaryKey(id);
/*  83 */       model.addAttribute("bean", bean);
/*     */     }
/*  85 */     return "admin/admin_view";
/*     */   }
/*     */   @RequestMapping(value={"/save"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   @ResponseBody
/*     */   public String save(Model model, Admin bean, Integer[] roleIds) {
/*  91 */     if (bean == null) {
/*  92 */       return "empty";
/*     */     }
/*  94 */     if (!Strings.isNullOrEmpty(bean.getPwd())) {
/*  95 */       bean.setPwd(DigestUtils.md5Hex(bean.getPwd()));
/*     */     }
/*     */ 
/*  98 */     Admin condition = new Admin();
/*  99 */     condition.setUsername(bean.getUsername());
/* 100 */     condition = (Admin)this.adminService.getByCondition(condition);
/* 101 */     if (bean.getId() == null)
/*     */     {
/* 103 */       if (condition != null) {
/* 104 */         return "userNameExist";
/*     */       }
/* 106 */       this.adminService.insertSelective(bean);
/*     */     }
/*     */     else {
/* 109 */       if ((condition != null) && (!condition.getId().equals(bean.getId()))) {
/* 110 */         return "userNameExist";
/*     */       }
/* 112 */       this.adminService.updateByPrimaryKeySelective(bean);
/*     */ 
/* 114 */       AdminRoles ar_condition = new AdminRoles();
/* 115 */       ar_condition.setAid(bean.getId());
/* 116 */       this.adminRolesService.delete(ar_condition, null);
/*     */     }
/*     */ 
/* 119 */     if ((roleIds != null) && (roleIds.length > 0)) {
/* 120 */       for (Integer roleId : roleIds) {
/* 121 */         AdminRoles role = new AdminRoles();
/* 122 */         role.setAid(bean.getId());
/* 123 */         role.setRid(roleId);
/* 124 */         this.adminRolesService.insertSelective(role);
/*     */       }
/*     */     }
/* 127 */     return "success";
/*     */   }
/*     */   @RequestMapping(value={"/del"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   @ResponseBody
/*     */   public String del(Integer id) {
/* 133 */     Admin bean = (Admin)this.adminService.selectByPrimaryKey(id);
/* 134 */     if (bean != null) {
/* 135 */       this.adminService.deleteByPrimaryKey(id);
/*     */ 
/* 137 */       AdminRoles ar_condition = new AdminRoles();
/* 138 */       ar_condition.setAid(id);
/* 139 */       this.adminRolesService.delete(ar_condition, null);
/*     */     }
/* 141 */     return "success";
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\s2mBlog.zip
 * Qualified Name:     s2mBlog-3.0.0.WEB-INF.classes.cc.s2m.web.s2mBlog.controller.admin.AdminController
 * JD-Core Version:    0.6.1
 */